﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;
using UBCon.Ribbon.Interfaces;

namespace UBCon.Ribbon
{
    //[System.Windows.StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(RibbonMenuItem))]
    public class RibbonMenuItem : ButtonBase, IRibbonControl
    {
        #region Constructors

        static RibbonMenuItem()
        {
            System.Type ownerType = typeof(RibbonMenuItem);
            RibbonMenuItem.DefaultStyleKeyProperty.OverrideMetadata(ownerType, new System.Windows.FrameworkPropertyMetadata(ownerType));
        }

        public RibbonMenuItem()
            : base()
        {
            
        }
        #endregion

        #region Properties

        public RibbonMenu DropDownSubmenu
        {
            get { return (RibbonMenu)GetValue(DropDownSubmenuProperty); }
            set { SetValue(DropDownSubmenuProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DropDownSubmenu.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty DropDownSubmenuProperty =
            System.Windows.DependencyProperty.Register("DropDownSubmenu", typeof(RibbonMenu), typeof(RibbonMenuItem), new System.Windows.FrameworkPropertyMetadata(null, new System.Windows.PropertyChangedCallback(RibbonMenuItem.OnDropDownSubmenuPropertyChanged)));

        public System.Windows.Media.ImageSource Image
        {
            get { return (System.Windows.Media.ImageSource)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Image.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty ImageProperty = RibbonButton.ImageProperty.AddOwner(typeof(RibbonMenuItem));

        
        public bool IsHighlighted
        {
            get { return (bool)GetValue(IsHighlightedProperty); }
        }

        // Using a DependencyProperty as the backing store for IsHighlighted.  This enables animation, styling, binding, etc...
        internal static readonly System.Windows.DependencyPropertyKey IsHighlightedPropertyKey =
            System.Windows.DependencyProperty.RegisterReadOnly("IsHighlighted", typeof(bool), typeof(RibbonMenuItem), new System.Windows.PropertyMetadata(false));

        public static readonly System.Windows.DependencyProperty IsHighlightedProperty = RibbonMenuItem.IsHighlightedPropertyKey.DependencyProperty;
        
        #endregion

        #region Depenency Property Changed Callbacks

        private static void OnDropDownSubmenuPropertyChanged(System.Windows.DependencyObject sender, System.Windows.DependencyPropertyChangedEventArgs e) 
        {
        
        }

     
        #endregion

        #region Overrides

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (this.Parent != null && this.Parent is RibbonMenu)
            {
                ParentMenu = this.Parent as RibbonMenu;
            }
        }

        //protected override void OnGotFocus(System.Windows.RoutedEventArgs e)
        //{
        //    SetIsHighlightedValue(true);
        //    base.OnGotFocus(e);
        //}

        //protected override void OnLostFocus(System.Windows.RoutedEventArgs e)
        //{
        //    base.OnLostFocus(e);
        //    if (IsHighlighted)
        //    {
        //        SetIsHighlightedValue(false);
        //    }
        //}

        //protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
        //{
        //    base.OnMouseEnter(e);
        //    //System.Windows.Input.Keyboard.Focus(this);
        //    Focus();
        //}

        //protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
        //{
        //    base.OnMouseLeave(e);
        //    System.Windows.Input.Keyboard.ClearFocus();
        //    if (IsHighlighted) 
        //    {
        //        SetIsHighlightedValue(false);
        //    }
        //}
       
        #endregion

        #region Private Utilities

        internal void SetIsHighlightedValue(bool value) 
        {
            SetValue(IsHighlightedPropertyKey, value);
        }

        #endregion

        #region Event Handlers
        #endregion

        #region Fields
        
        private RibbonMenu ParentMenu;
        
        #endregion

        #region Events
        #endregion

        #region IRibbonControl Implementation

        /// <summary>
        /// Gets a boolean value indicating whether the contol's size is large
        /// </summary>
        public bool IsLarge
        {
            get { return false; }
        }

        #endregion
    }
}
